package cn.supermarket.controller;

import cn.supermarket.pojo.dto.ReceivingDTO;
import cn.supermarket.pojo.vo.ReceivingVO;
import cn.supermarket.service.iservice.IReceivingService;
import cn.supermarket.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/receiving")
@Slf4j
@Api(tags = "提货单处理模块")
public class ReceivingController extends BaseController {

    @Autowired
    private IReceivingService receivingService;


    @ApiOperation("添加提货单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId",value = "订单号",example = "123456"),
            @ApiImplicitParam(name = "date",value = "提货日期",example = "2022-7-13"),
            @ApiImplicitParam(name = "consignee",value = "提货人",example = "张三"),
            @ApiImplicitParam(name = "productId",value = "商品编号",example = "123456"),
            @ApiImplicitParam(name = "productName",value = "商品名称",example = "西瓜"),
            @ApiImplicitParam(name = "unit",value = "单位",example = "斤"),
            @ApiImplicitParam(name = "count",value = "数量",example = "3.6"),
            @ApiImplicitParam(name = "appRover",value = "审批人",example = "李四"),
            @ApiImplicitParam(name = "operator",value = "操作人员",example = "王五"),
            @ApiImplicitParam(name = "remark",value = "备注",example = "无")
    })
    @PostMapping("/add")
    public JsonResult<String> addReceiving( ReceivingDTO receivingDTO){
        log.info("123456");
        System.out.println("receivingDTO = " + receivingDTO);
        receivingService.addReceiving(receivingDTO);
        return JsonResult.ok("添加成功");
    }

    @GetMapping("/update/remark")
    @ApiOperation("修改备注操作")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "id",name = "id",required = true,dataType = "id"),
            @ApiImplicitParam(value = "备注",name = "remark",required = true,dataType = "String")
    })
    public JsonResult<Void> updateRemark(Long id,String remark){
        receivingService.updateRemark(id, remark);
        return JsonResult.ok();
    }

    @GetMapping("/update/isDisplay")
    @ApiOperation("修改是否显示操作")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "id",name = "id",required = true,dataType = "id"),
            @ApiImplicitParam(value = "是否显示",name = "isDisplay",required = true,dataType = "int")
    })
    public JsonResult<Void> updateIsDisplay(Long id,Integer isDisplay){
        receivingService.updateIsDisplay(id, isDisplay);
        return JsonResult.ok();
    }

    @GetMapping("/update/isCancel")
    @ApiOperation("修改是否作废操作")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "id",name = "id",required = true,dataType = "id"),
            @ApiImplicitParam(value = "是否作废",name = "isisCancel",required = true,dataType = "int")
    })
    public JsonResult<Void> updateIsCancel(Long id,Integer isCancel){
        receivingService.updateIsCancel(id, isCancel);
        return JsonResult.ok();
    }

    @GetMapping("/select/orderId")
    @ApiOperation("根据订单号查询信息")
    @ApiImplicitParam(value = "订单号",name = "orderId",required = true,dataType = "long")
    public JsonResult<List<ReceivingVO>> getByOrderId(Long orderId){
        List<ReceivingVO> receivingVOS = receivingService.selectByOrderId(orderId);
        return JsonResult.ok(receivingVOS);
    }

    @GetMapping("/select/date")
    @ApiOperation("根据日期查询信息")
    @ApiImplicitParam(value = "日期",name = "date",required = true,dataType = "Date")
    public JsonResult<List<ReceivingVO>> getByDate(Date date){
        List<ReceivingVO> receivingVOS = receivingService.selectByDate(date);
        return JsonResult.ok(receivingVOS);
    }

    @GetMapping("/select/consignee")
    @ApiOperation("根据提货人查询信息")
    @ApiImplicitParam(value = "提货人",name = "consignee",required = true,dataType = "String")
    public JsonResult<List<ReceivingVO>> getByReturner(String consignee){
        List<ReceivingVO> receivingVOS = receivingService.selectByConsignee(consignee);
        return JsonResult.ok(receivingVOS);
    }


}
